package com.ys.fmms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ys.fmms.mapper.VideoMapper;
import com.ys.fmms.pojo.Video;
import com.ys.fmms.service.VideoService;
import com.ys.fmms.util.TimeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Transactional
@Service(value = "videoServiceImpl")
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {
    @Override
    public List<Video> getVideoList() {
        QueryWrapper<Video> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");
        List<Video> videoList = baseMapper.selectList(wrapper);
        List<Video> collect = videoList.stream().map(item -> {
            Video video = new Video();
            BeanUtils.copyProperties(item, video);
            video.setType("video/mp4");
            return video;
        })
                .collect(Collectors.toList());
        return collect;
    }

    @Override
    public void saveVideoInfo(String fileName, String newFileName, String videoUrl) {
        Video video = new Video();
        video.setSrc(videoUrl);
        video.setCreateTime(TimeUtils.currentDate());
        video.setRemark(fileName);
        video.setVideoName(newFileName);
        baseMapper.insert(video);
    }
}
